/*
 * Copyright (c) 2013 Andaily Information Technology Co. Ltd
 * www.andaily.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Andaily Information Technology Co. Ltd ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you
 * entered into with Andaily Information Technology Co. Ltd.
 */
package top.suven.http.oauth.validator;


import org.apache.oltu.oauth2.as.request.AbstractOAuthTokenRequest;
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;


/**
 * 2018-08-01
 * <p/>
 *  OauthAccessToken 信息
 * 定义OAuth2 的客户端(client details)
 *  grant_type="authorization_code"
 *  DBTable: oauth_client_details
 *  3.密码模式（resource owner password credentials）
 *
 * @author suven.wang
 */

/**
 *  /oauth/token?client_id=mobile-client&client_secret=mobile&grant_type=password&scope=read,write&username=mobile&password=mobile
 **/

public class GrantTypePasswordClientValidator extends AbstractOauthGrantTypeValidator {




    public GrantTypePasswordClientValidator(AbstractOAuthTokenRequest oauthRequest) {
        super(oauthRequest);
    }

    /*
    * /oauth/token?client_id=mobile-client&client_secret=mobile&grant_type=password&scope=read,write&username=mobile&password=mobile
    * */
    @Override
    protected boolean validateSelf() throws OAuthSystemException {
        // 前4点 基于token 验证于AbstractOauthTokenValidator 抽象
        if(!this.validateGrantType()){
            return false;
        }
        //5.个性业务实现validate username,password
        long userId = validateUsernamePassword();
        if (userId <= 0) {
            return false;
        }
        if(!validateAccessToken(userId)){
            return false;
        }
        return true;
    }







}
